package tetris;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

/**
 * Creates a Game Over Menu after game finish.
 * @author dejvid
 *
 */
class GameOverMenu extends JPanel {

	private static final long serialVersionUID = 1L;
	private JButton btnPlayAgain;
    private JButton btnViewHighScores;
    private JButton btnExitGame;
    private	JTextPane goInfo; 
    private JTextField gameOverText;
    static boolean temp = false;
    
    /**
     * Creates a window after finishing game.
     * Creates buttons: PLAY AGAIN, VIEW HIGHSCORES, EXIT GAME.
     * Creates textFields: GAME OVER, Your Nickname, Your Score.
     */
	public GameOverMenu() {
		
		setVisible(true);
		setLayout(null);
		setSize(300,600);
		gameOverText = new JTextField();
    	gameOverText.setBounds(0, 5, 300, 74);
    	gameOverText.setEditable(false);
    	gameOverText.setFont(new Font("OCR A Std", Font.PLAIN, 38));
    	gameOverText.setBackground(Color.DARK_GRAY);
    	gameOverText.setForeground(Color.WHITE);
    	gameOverText.setText("GAME OVER");
    	gameOverText.setColumns(10);
    	gameOverText.setBorder(null);
    	gameOverText.setFocusable(false);
    	gameOverText.setHorizontalAlignment(JTextField.CENTER);
    	gameOverText.setDoubleBuffered(true);
    	add(gameOverText);
		
		btnPlayAgain = new JButton(" PLAY AGAIN ");
    	add(btnPlayAgain);
		btnPlayAgain.setBackground(Color.ORANGE);
		btnPlayAgain.setFont(new Font("Courier", Font.BOLD, 20));	
		btnPlayAgain.setOpaque(true);
		btnPlayAgain.setBorder(null);
		btnPlayAgain.setDoubleBuffered(true);
		btnPlayAgain.setBounds(72, 240, 155, 43);
		btnPlayAgain.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				GameMenu gm = new GameMenu();
				gm.startGame();
				setVisible(false);
			}
		});
		btnPlayAgain.addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseMoved(MouseEvent arg0) {
				btnPlayAgain.setBackground(Color.RED);
			}
		});
		
		btnViewHighScores = new JButton(" HIGH SCORES ");
		add(btnViewHighScores);
		btnViewHighScores.setBackground(Color.ORANGE);
		btnViewHighScores.setFont(new Font("Courier", Font.BOLD, 19));
		btnViewHighScores.setOpaque(true);
		btnViewHighScores.setBorder(null);
		btnViewHighScores.setDoubleBuffered(true);
		btnViewHighScores.setBounds(72, 329, 155, 43);
		btnViewHighScores.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				GameMenu gm = new GameMenu();
				gm.viewHighScores();
			}
		});
		btnViewHighScores.addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseMoved(MouseEvent arg0) {
				btnViewHighScores.setBackground(Color.RED);
			}
		});
		
		btnExitGame = new JButton(" EXIT GAME ");
		add(btnExitGame);
		btnExitGame.setBackground(Color.ORANGE);
		btnExitGame.setFont(new Font("Courier", Font.BOLD, 21));
		btnExitGame.setOpaque(true);
		btnExitGame.setBorder(null);
		btnExitGame.setDoubleBuffered(true);
		btnExitGame.setBounds(72, 419, 155, 43);
		btnExitGame.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				System.exit(0);
			}
		});
		btnExitGame.addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseMoved(MouseEvent arg0) {
				btnExitGame.setBackground(Color.RED);
			}
		});
		
		addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseMoved(MouseEvent arg0) {
				btnPlayAgain.setBackground(Color.ORANGE);
				btnViewHighScores.setBackground(Color.ORANGE);
				btnExitGame.setBackground(Color.ORANGE);
			}
		});
		
		goInfo = new JTextPane();
		goInfo.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
		goInfo.setForeground(Color.ORANGE);
		goInfo.setBackground(Color.DARK_GRAY);
		goInfo.setText("\n       Your nickname:\t" +InsertName.nickname +"\n       Your score:\t" +GamePanel.finalScore);
		goInfo.setBounds(0, 104, 300, 74);
		goInfo.setEditable(false);
		goInfo.setFocusable(false);
		add(goInfo);
	}

}
